home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / char.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  2KB  |  131 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1988 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    Febuary 1988.
  6.  *
  7.  *    %W%    %G%
  8. */
  9. #include "fig.h"
  10. #include "resources.h"
  11. #include "font.h"
  12. #include "paintop.h"
  13.  
  14. extern int        cur_x, cur_y;
  15.  
  16. #define            BUF_SIZE    80
  17. #define            CR        13
  18. #define            CTRL_U        21
  19. #define            SP        32
  20. #define            DEL        127
  21. #define            CTRL_H        8
  22.  
  23. #ifdef AMIGA    
  24. unsigned char        prefix[BUF_SIZE], suffix[BUF_SIZE];
  25. #else
  26. char            prefix[BUF_SIZE], suffix[BUF_SIZE];
  27. #endif
  28. int            leng_prefix, leng_suffix;
  29.  
  30. static PIX_FONT        font;
  31. static PIXWIN        pw;
  32. static int        char_ht, char_wid;
  33. static int        char_received;
  34. static int        base_x, base_y;
  35.  
  36. static            (*cr_proc)();
  37.  
  38. static
  39. draw_cursor(x, y)
  40. int    x, y;
  41. {
  42.     pw_vector(pw, x, y, x, y-char_ht, INV_PAINT, 1);
  43.     }
  44.  
  45. initialize_char_handler(p, f, cr, bx, by)
  46. PIXWIN        p;
  47. PIX_FONT        f;
  48. int        (*cr)();
  49. int        bx, by;
  50. {
  51.     pw = p;
  52.     font = f;
  53.     cr_proc = cr;
  54.     base_x = bx;
  55.     base_y = by;
  56.  
  57.     char_wid = char_width(f);
  58.     char_ht = char_height(f);
  59.     char_received = 0;
  60.     turn_on_blinking_cursor(draw_cursor, draw_cursor,
  61.                 cur_x, cur_y, (long)0, (long)700000);
  62.     }
  63.  
  64. terminate_char_handler()
  65. {
  66.     turn_off_blinking_cursor();
  67.     cr_proc = NULL;
  68.     return(char_received);
  69.     }
  70.  
  71. erase_char_string()
  72. {
  73.     pw_text(pw, base_x, base_y, INV_PAINT, font, prefix);
  74.     if (leng_suffix) pw_text(pw, cur_x, base_y, INV_PAINT, font, suffix);
  75.     }
  76.  
  77. draw_char_string()
  78. {
  79.     pw_text(pw, base_x, base_y, INV_PAINT, font, prefix);
  80.     if (leng_suffix) pw_text(pw, cur_x, base_y, INV_PAINT, font, suffix);
  81.     move_blinking_cursor(cur_x, cur_y);
  82.     }
  83.  
  84. char_handler(c)
  85. #ifdef AMIGA
  86. unsigned char    c;
  87. #else
  88. char    c;
  89. #endif
  90. {
  91.     if (c == CR) {
  92.         cr_proc();
  93.         }
  94.     else if (c == DEL || c == CTRL_H) {
  95.         if (leng_prefix > 0) {
  96.         erase_char_string();
  97.         char_received = 1;
  98.         cur_x -= char_wid;
  99.         prefix[--leng_prefix] = '\0';
  100.         draw_char_string();
  101.         }
  102.         }
  103.     else if (c == CTRL_U) {
  104.         if (leng_prefix > 0) {
  105.         erase_char_string();
  106.         char_received = 1;
  107.         cur_x = base_x;
  108.         leng_prefix = 0;
  109.         *prefix = '\0';
  110.         draw_char_string();
  111.         }
  112.         }
  113. #ifdef AMIGA
  114.     else if (c < SP || (c > 127 && c < 160)) {
  115. #else
  116.     else if (c < SP) {
  117. #endif
  118.         }
  119.     else if (leng_prefix+leng_suffix == BUF_SIZE) {
  120.         put_msg("Text buffer is full, character is ignored");
  121.         }
  122.     else {
  123.         erase_char_string();
  124.         char_received = 1;
  125.         cur_x += char_wid;
  126.         prefix[leng_prefix++] = c;
  127.         prefix[leng_prefix] = '\0';
  128.         draw_char_string();
  129.         }
  130.     }
  131.